<?php
class Site_Model_Observer_AttacheNews extends Promotor_Observable_Observer_Abstract {
	public function update(Promotor_Observable_List $list, $newsId = null) {
		$rq = $this->getRequest();
		if ((null === ($sites = $rq->getPost('categorytab')))) {
			$this->_setStatus(self::NULL);
			return;
		}
		if (is_array($newsId)) {
			$newsId = isset($newsId['id'])
				? $newsId['id']
				: current($newsId);
		}
		if (null === $newsId) {
			$this->_setStatus(self::NULL);
			return;
		}

		$hasNews = new Site_Model_HasNews();
		$hasNews->attachNewsToSites($newsId, (array) @$sites['tree']);

		$status = $hasNews->getStatus();

		$this->_setStatus($status);
		$this->_setMessages($hasNews->getMessages(false));
		$this->_exception = $hasNews->getExceptions();
	}
}